<script type="text/javascript">
    $(function () {
        $("#btnSave").click(function () {
            var flag = false;
            $("#saveForm").find("input[isNull]").each(function(){
                var inputValue = $(this).val();
                if(undefined == inputValue || null == inputValue || "" == inputValue){
                    addError($(this),$(this).attr("isNull")+"不能为空.");
                    flag = false;
                    return false;
                }else{
                    flag = true;
                }
            });

            if(flag == false){
                return;
            }
            $("#btnSave").blur();
            showLoading();
            fy_api.ajaxSubmit($("#saveForm"),{
                success: function (data) {
                    hideLoading();
                    if (!isSuccess(data)) {
                        $.messager.alert('系统提示', data.msg, 'error', function () {
                            self.focus();
                        });
                    } else {
                        parent.grid_get("grid").datagrid("load");
                        turnBack();
                    }
                }
            });

            var keyId = (getUrlParam("keyId", url));
            fy_api.load_template({

                controller: $("#saveForm").attr("templateParam", "keyId=" + keyId), loading: true, initValue: true, loaded: function(){
                    if(keyId == ""){
                        //添加
                        $("#divEdit").remove();
                        $("#saveForm").attr("action","miniProgram/save.do")
                    }
                    loaded();
                }
            });
        });
        var keyId = (getUrlParam("keyId", url));
        if(keyId != ""){
            //编辑
            fy_api.load_template({
                controller: $("#saveForm").attr("templateParam", "keyId=" + keyId), loading: true, initValue: true, loaded: function(){
                    loaded(keyId);
                }
            });
        }else{
            //添加
            $("#divEdit").remove();
            fy_api.load_template({
                controller: $("#saveForm").attr("templateParam", "keyId=" + keyId), loading: true,initValue: true, loaded: function(){
                    loaded(keyId);
                    $("#saveForm").attr("action","miniProgram/save.do")
                }
            });
        }

    });

    function turnBack() {
        parent.j_closeWin();
    }

    function loaded(keyId){
        $('#company').inputgrid({
            textField: 'o.code',
            searchField: ['o.code', 'o.name'],//查询字段多字段匹配
            columns: [[
                {field: 'o.code', title: '金融代码'},
                {field: 'o.name', title: '名称'},
                {field: 'o.address', title: '地址'}
            ]],
            _page: parent.page_list,
            _append: [],//隐藏列
            _table: "company as o",
            _db: "slave"
        });
    }
</script>
<style>
    .div-label {
        width: 190px
    }

    .div-item{
        width : 90%
    }

    .div-item input{
        width : 90%
    }

    tr{
        width : 90%
    }

</style>
<form action="miniProgram/update.do" method="post" id="saveForm" templateUrl="miniProgram/get.do">
    <div id="divEdit">
        <input type="hidden" name="id" value="${id}"/>
        <input type="hidden" name="deleteFlag" value="${deleteFlag}"/>
    </div>
    <table style="margin: 10px auto;padding: 10px">
        <tr>
            <td>
                <div class="div-label">应用ID：</div>
            </td>
            <td style="width: 80%;">
                <div class="div-item">
                    <input type="text" name="appid" value="${appid}" isNull/>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="div-label">应用名称：</div>
            </td>
            <td>
                <div class="div-item">
                    <input type="text" name="appName" value="${appName}" isNull/>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="div-label">密钥：</div>
            </td>
            <td>
                <div class="div-item">
                    <input type="text" name="secret" value="${secret}" isNull/>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="div-label">金融代码：</div>
            </td>
            <td>
                <div class="div-item">
                    <input type="text" name="tenantCode" id="company" value="${tenantCode}"/>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="div-label">交易中心URL：</div>
            </td>
            <td>
                <div class="div-item">
                    <input type="text" name="tradingcenterUrl" id="tradingcenterUrl" value="${tradingcenterUrl}"/>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="div-label">交易中心商户Key：</div>
            </td>
            <td>
                <div class="div-item">
                    <input type="text" name="tradingcenterMchKey" id="tradingcenterMchKey" value="${tradingcenterMchKey}"/>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="div-label">备注：</div>
            </td>
            <td colspan="3">
                <div class="div-item" style="width: 90%">
                    <input type="text" name="remark" value="${remark}" />
                </div>
            </td>
        </tr>
    </table>
</form>
<div class="form-buttons">
    <a id="btnSave" class="easyui-linkbutton" iconCls="icon-save">保存</a>
    <a id="btnBack" class="easyui-linkbutton c2" iconCls="icon-undo" onClick="turnBack();">返回</a>
</div>
